<template>
	<view class="content">
		<view class="prodlist">
			<view class="prod-item" v-for="(item,index) in productlist" :key="index" @click="goproduct(item)">
				<image mode="aspectFill" :src="item.productinfo.cover_image" class="prdimage"></image>
				<view class="right">
					<text>{{item.productinfo.name}}</text>
					 <view class="bottomoper">
						 <text class="price">{{item.productinfo.sales_price}}元</text>
					     <text class="delbtn" @click.stop.prevent="stopPrevent" @click="delfav(item)">删除</text>
					 </view>
					
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadingType:"more",
					page: 1,
				productlist:[]
			}
		},
		onLoad(option) {
			this.getFavlist();
		},
		methods: {
			goproduct(item){
				let id = item.jyshop_product_id;
		 
				let gourl = `/pages/product/product?id=`;
				if (item.activity_type == "pin") {
					gourl = `/pages/product/productpin?id=`;
				}
				
				uni.navigateTo({
					url: gourl + id
				})
			},
			 stopPrevent() {},
			getFavlist(){
				let that = this;
				let params = {
					page:that.page,
					pagesize:6
				}
				this.$util.req("/user/getFavList",params,true,function(res){
					that.productlist = res.data;
					that.page=that.page+1;
					that.loadingType = res.data.length<params.pagesize ? 'nomore':"more";
				});
			},
			delfav(item){
				let that = this;
				uni.showModal({
				    content: '确定要删除么',
				    success: (e)=>{
				    	if(e.confirm){
				    	 this.$util.req("/user/delfav",{id:item.id},true,function(res){
				    	 	that.page=1;
				    	 	that.getFavlist();
				    	 });
				    	}
				    }
				});
			
			}
			
		}
	}
</script>

<style lang="scss">
page,.content {
		background: $page-color-base;
		height: 100%;
	}

	.prodlist{
		display: flex;
		flex-direction: column;
	
		.prod-item{
			color: $font-color-dark;
			margin-bottom: 20upx;
			background-color: #FFFFFF;
			display: flex;
			padding: 10upx;	
			image{
				width: 150upx;
				height: 150upx;
			}
			.right{
				flex:1;
				padding-left: 10upx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
			 .price {
			 	font-size: $font-base + 2upx;
			 	color: #FF5A5F;
			 
			 	&:before {
			 		content: '￥';
			 		font-size: $font-sm;
			 		margin: 0 2upx 0 8upx;
			 	}
			 }
			 .bottomoper{ 
				width: 100%;
			 	display: flex;
			 	align-items: baseline; 
			 	justify-content: space-between;
				.delbtn{
					color: $font-color-dark;
					font-size: $font-base;
					padding: 10upx;
				}
			 	
			 }
			 
			}
		}
		
	}
	
</style>
